package com.hig.ledger.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hig.ledger.mapper.LedgerMeasuringInstrumentMapper;
import com.hig.ledger.domain.LedgerMeasuringInstrument;
import com.hig.ledger.service.ILedgerMeasuringInstrumentService;

/**
 * 计量器具台账Service业务层处理
 *
 * @author ruoyi
 * @date 2024-09-22
 */
@Service
public class LedgerMeasuringInstrumentServiceImpl implements ILedgerMeasuringInstrumentService
{
    @Autowired
    private LedgerMeasuringInstrumentMapper ledgerMeasuringInstrumentMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询计量器具台账
     *
     * @param id 计量器具台账ID
     * @return 计量器具台账
     */
    @Override
    public LedgerMeasuringInstrument selectLedgerMeasuringInstrumentById(Long id)
    {
        return ledgerMeasuringInstrumentMapper.selectLedgerMeasuringInstrumentById(id);
    }

    /**
     * 查询计量器具台账列表
     *
     * @param ledgerMeasuringInstrument 计量器具台账
     * @return 计量器具台账
     */
    @Override
    @DataScope(deptAlias = "d")
    public List<LedgerMeasuringInstrument> selectLedgerMeasuringInstrumentList(LedgerMeasuringInstrument ledgerMeasuringInstrument)
    {
        return ledgerMeasuringInstrumentMapper.selectLedgerMeasuringInstrumentList(ledgerMeasuringInstrument);
    }

    /**
     * 新增计量器具台账
     *
     * @param ledgerMeasuringInstrument 计量器具台账
     * @return 结果
     */
    @Override
    public int insertLedgerMeasuringInstrument(LedgerMeasuringInstrument ledgerMeasuringInstrument)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ledgerMeasuringInstrument.setCreateBy(loginUser.getUser().getUserName());
        ledgerMeasuringInstrument.setDeptId(loginUser.getUser().getDeptId());
//        long id = ledgerMeasuringInstrumentMapper.getNextId();
//        ledgerMeasuringInstrument.setId(id);
        ledgerMeasuringInstrument.setCreateTime(DateUtils.getNowDate());
        return ledgerMeasuringInstrumentMapper.insertLedgerMeasuringInstrument(ledgerMeasuringInstrument);
    }

    /**
     * 修改计量器具台账
     *
     * @param ledgerMeasuringInstrument 计量器具台账
     * @return 结果
     */
    @Override
    public int updateLedgerMeasuringInstrument(LedgerMeasuringInstrument ledgerMeasuringInstrument)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ledgerMeasuringInstrument.setUpdateBy(loginUser.getUser().getUserName());
        ledgerMeasuringInstrument.setUpdateTime(DateUtils.getNowDate());
        return ledgerMeasuringInstrumentMapper.updateLedgerMeasuringInstrument(ledgerMeasuringInstrument);
    }

    /**
     * 批量删除计量器具台账
     *
     * @param ids 需要删除的计量器具台账ID
     * @return 结果
     */
    @Override
    public int deleteLedgerMeasuringInstrumentByIds(Long[] ids)
    {
        return ledgerMeasuringInstrumentMapper.deleteLedgerMeasuringInstrumentByIds(ids);
    }

    /**
     * 删除计量器具台账信息
     *
     * @param id 计量器具台账ID
     * @return 结果
     */
    @Override
    public int deleteLedgerMeasuringInstrumentById(Long id)
    {
        return ledgerMeasuringInstrumentMapper.deleteLedgerMeasuringInstrumentById(id);
    }
}
